package com.gitee.wsl.compose.ui.richtext.edit.model.paragraph.type.list

import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.gitee.wsl.compose.ui.richtext.edit.annotation.ExperimentalRichTextApi
import com.gitee.wsl.compose.ui.richtext.edit.model.DefaultListIndent
import com.gitee.wsl.compose.ui.richtext.edit.model.span.RichSpan
import com.gitee.wsl.compose.ui.richtext.edit.model.paragraph.api.ConfigurableListLevel
import com.gitee.wsl.compose.ui.richtext.edit.model.paragraph.api.ConfigurableStartTextWidth
import com.gitee.wsl.compose.ui.richtext.edit.model.paragraph.type.ParagraphType
import com.gitee.wsl.reflect.LazyVar

abstract class AbstractList(
    initialIndent: Int = DefaultListIndent,
    startTextWidth: TextUnit = 0.sp,
    initialLevel:Int = 1,
) : ParagraphType, ConfigurableStartTextWidth, ConfigurableListLevel {

    override var startTextWidth: TextUnit = startTextWidth
        set(value) {
            field = value
            style = getNewParagraphStyle()
        }

    protected var indent:Int = initialIndent
        set(value) {
            field = value
            style = getNewParagraphStyle()
        }

    override var level:Int = initialLevel
        set(value) {
            field = value
            style = getNewParagraphStyle()
        }

    protected var style: ParagraphStyle by LazyVar { getNewParagraphStyle() }

    protected abstract fun getNewParagraphStyle():ParagraphStyle


    @OptIn(ExperimentalRichTextApi::class)
    override var startRichSpan: RichSpan by LazyVar {  getNewStartRichSpan() }

    protected abstract fun getNewStartRichSpan(textRange: TextRange = TextRange(0)): RichSpan

}